<template>
  <div class="bgc-default">
    <div class="pad-20 bg-color-white">
      <!--顶部搜索 -->
      <div class="top-operate-default flex-col" style="align-items: baseline; padding: 20px 0; height: 100%; ">
        <div class="pad-l-20">
          <label>搜索内容：</label>
          <el-select class="width-160" v-model="textCol">
            <el-option label="申请人名称" value="applyName"></el-option>
            <el-option label="申请人手机" value="applyPhone"></el-option>
            <el-option label="销方名称开票单号" value="invoiceCode"></el-option>
            <el-option label="平台单号" value="platformOrderNo"></el-option>
            <el-option label="系统单号" value="systemOrderNo"></el-option>
            <el-option label="发票抬头" value="invoiceRise"></el-option>
            <el-option label="单位税号" value="distinguishNum"></el-option>
            <el-option label="单位地址" value="registerAddress"></el-option>
            <el-option label="单位电话" value="taxPhone"></el-option>
            <el-option label="开户银行" value="accountBankInfo"></el-option>
            <el-option label="银行账号" value="bankCardNo"></el-option>
            <el-option label="备注" value="remark"></el-option>
          </el-select>
          <el-input @keyup.enter.native="handleSearch" v-model="textValue" class="width-235" placeholder="请输入关键词">
          </el-input>
          <label class="mar-l-20">时间筛选：</label>
          <el-select class="width-120" v-model="timeCol">
            <el-option label="申请时间" value="createTime"></el-option>
            <el-option label="开票时间" value="passTime"></el-option>
            <el-option label="邮寄时间" value="mailingTime"></el-option>
            <el-option label="拒绝时间" value="rejectTime"></el-option>
            <el-option label="作废时间" value="voidTime"></el-option>
          </el-select>
          <el-date-picker v-model="timeValue" type="datetimerange" range-separator="至"
            value-format="yyyy-MM-dd HH:mm:ss" :default-time="['00:00:00', '23:59:59']" start-placeholder="开始日期"
            end-placeholder="结束日期">
          </el-date-picker>
        </div>
        <div class="pad-l-20 mar-t-10">
          <label>抬头类型：</label>
          <el-select v-model="searchListQuery.invoiceRiseType" style="width:150px;">
            <el-option label="全部" value=""></el-option>
            <el-option label="个人" value="0"></el-option>
            <el-option label="企业" value="1"></el-option>
          </el-select>
          <label class="mar-l-20">发票类型：</label>
          <el-select v-model="searchListQuery.invoiceType" style="width:150px;">
            <el-option label="全部" value=""></el-option>
            <el-option label="增值税普通发票" value="0"></el-option>
            <el-option label="增值税专用发票" value="1"></el-option>
          </el-select>
          <label class="mar-l-20">开票内容：</label>
          <el-select v-model="searchListQuery.invoiceContentId" class="width-160">
            <el-option label="全部" value=""></el-option>
            <el-option v-for="(item, index) in invoiceContentList" :key="index" :label="item.invoiceContent"
              :value="item.invoiceContentId">
            </el-option>
          </el-select>
          <el-button-group class="mar-l-20">
            <el-button type="primary" @click="handleSearch">查询</el-button>
            <el-button plain @click="resetSearch">重置</el-button>
          </el-button-group>
        </div>
      </div>
      <!--开票状态 -->
      <div class="tabs-box mar-t-15">
        <el-tabs type="card" v-model="invoiceStatus" @tab-click="invoiceStatusClick">
          <el-tab-pane :label="allLabel" name="-1"></el-tab-pane>
          <el-tab-pane :label="waitCheckLabel" name="1"></el-tab-pane>
          <el-tab-pane :label="waitMailedLabel" name="2"></el-tab-pane>
          <el-tab-pane :label="alreadyMailedLabel" name="3"></el-tab-pane>
          <el-tab-pane :label="notPassLabel" name="4"></el-tab-pane>
          <el-tab-pane :label="abolishedLabel" name="5"></el-tab-pane>
        </el-tabs>
      </div>

      <!-- 全选、操作 -->
      <div class="v-align-c">
        <div class="pad-t-15 pad-b-15 font-14 v-align-c" v-if="invoiceStatus == '1'">
          <el-checkbox class="mar-l-14 mar-r-0" v-model="allChecked" @change="selectAll"><span
              class="mar-l-20">当页全选</span></el-checkbox>
          <span class="pad-l-4 pad-r-4">|</span>
          <div class="width-80">已选{{multipleSelection.length}}项</div>
          <el-button class="batch-btn" @click="batchApproved">批量通过</el-button>
        </div>
        <div class="mar-t-10">
          <span>已开票合计金额：￥{{alreadyOpenedAmount}}</span>
          <span class="mar-l-15">
            <el-button type="text" @click="openOrderList(2)">详情</el-button>
          </span>
          <span class="mar-l-15">待审核合计金额：￥{{pendingReviewAmount}}</span>
          <span class="mar-l-15">
            <el-button type="text" @click="openOrderList(1)">详情</el-button>
          </span>
        </div>
      </div>
      <div class="mar-t-5" v-loading="listLoading" element-loading-text="拼命加载中"
        element-loading-spinner="el-icon-loading" element-loading-background="rgba(255, 255, 255, 0.5)"
        style="min-height: 695px;">
        <el-row style="background: #F7F8FA" class="pad-10" :gutter="10">
          <el-col :span="3">申请人信息</el-col>
          <el-col :span="3">开票金额</el-col>
          <el-col :span="3">开票内容</el-col>
          <el-col :span="4">发票详情</el-col>
          <el-col :span="3">收件人信息</el-col>
          <el-col :span="4">时间</el-col>
          <el-col :span="2">状态</el-col>
          <el-col :span="2">操作</el-col>
        </el-row>
        <div class="pad-t-10"></div>
        <div v-for="(item, index) of dataList" :key="index">
          <el-row class="pad-10 v-align-c" :gutter="10" style="background:#F2F6FF">
            <el-col :span="3">
              <div class="flex">
                <el-checkbox v-if="invoiceStatus == '1'" v-model="item.checked" @change="checkedChange(item.checked)"
                  class="v-align-c"></el-checkbox>
                <div class="flex-col mar-l-4">
                  <span>类型：{{ item.applyType == 0 ? '经销商' : ''}}</span>
                  <span>名称：{{ item.applyName }}</span>
                  <span>手机：{{ item.applyPhone }}</span>
                </div>
              </div>
            </el-col>
            <el-col :span="3">
              <div>
                <span>
                  <el-tooltip class="item" effect="dark" :content="'开票单号:' + item.invoiceCode" placement="top-start">
                    <el-button :class="item.invoiceMethod == 0 ? 'apply_class':'platform_class'">
                      {{ invoiceMethod[item.invoiceMethod] }}
                    </el-button>
                  </el-tooltip>
                  <span>￥{{ item.amount }}</span>
                  <div class="font-red font-12" v-if="item.invoiceMethod == 1 && item.freight && item.freight > 0">(
                    包含运费：￥{{ item.freight }} )</div>
                  <el-popover placement="right" width="720" trigger="click">
                    <el-table :data="item.projectOrderDTOList" class="pop-layer-tab" style="width: 100%" height="320">
                      <el-table-column v-if="item.invoiceMethod === 0" label="开票金额(分销价)" align="left">
                        <template slot-scope="scope">
                          ￥{{ scope.row.distributeTotalPrice }}
                        </template>
                      </el-table-column>
                      <el-table-column label="订单金额" align="left">
                        <template slot-scope="scope">
                          ￥{{ scope.row.orderPrice }}
                        </template>
                      </el-table-column>
                      <el-table-column label="订单号" width="280px" align="left">
                        <template slot-scope="scope">
                          <div class="flex-col">
                            <span>平台单号:
                              <img class="width-16 height-16" :src="iconList[scope.row.externalPlatformType]" />
                              {{ scope.row.externalOrderNo }}
                            </span>
                            <span>系统单号:{{ scope.row.orderNo }}</span>
                          </div>
                        </template>
                      </el-table-column>
                      <el-table-column width="100" label="操作">
                        <template slot-scope="scope">
                          <el-button type="text" @click="openOrderDetail(scope.row)">订单详情</el-button>
                        </template>
                      </el-table-column>
                    </el-table>
                    <el-button slot="reference" type="text">详情</el-button>
                  </el-popover>
                </span>
              </div>
            </el-col>
            <el-col :span="3">{{ item.invoiceContent }}</el-col>
            <el-col :span="4">
              <div class="flex-col">
                <span>抬头类型：{{ item.invoiceRiseType == 0 ? '个人' : '企业' }}</span>
                <span>发票类型：{{ item.invoiceType == 0 ? '增值税普通发票' : '增值税专用发票' }}</span>
                <span>发票抬头：{{ item.invoiceRise }}</span>
                <span v-if="item.invoiceRiseType == 1">单位税号：{{ item.distinguishNum }}</span>
                <span>备注：{{ item.remark }}</span>
              </div>
            </el-col>
            <el-col :span="3">
              <div class="flex-col">
                <span>收件人：{{ item.recipient }}</span>
                <span>电话：{{ item.receiptPhone }}</span>
                <span>地址：{{ item.receiptAddress }}</span>
              </div>
            </el-col>
            <el-col :span="4">
              <div class="flex-col">
                <span>申请时间：{{ item.createTime }}</span>
                <span>开票时间：{{ item.passTime }}</span>
                <span>邮寄时间：{{ item.mailingTime }}</span>
                <span>拒绝时间：{{ item.rejectTime }}</span>
                <span>作废时间：{{ item.voidTime }}</span>
              </div>
            </el-col>
            <el-col :span="2">
              <span v-if="item.status == 1">待审核</span>
              <span v-if="item.status == 2">待邮寄</span>
              <span v-if="item.status == 3">已寄出</span>
              <span v-if="item.status == 4">未通过</span>
              <span v-if="item.status == 5">已作废</span>
              <el-popover placement="top" width="220" v-if="item.status == 3 || item.status == 5" trigger="click">
                <div class="flex-col">
                  <span>快递公司：{{ item.expressName }}</span>
                  <span>快递单号：{{ item.trackingNo }}</span>
                </div>
                <el-button slot="reference" type="text">物流</el-button>
              </el-popover>
              <el-popover placement="top" width="220" v-if="item.status == 4 || item.status == 5" trigger="click">
                <div class="flex-col">
                  <span>{{ item.status == 4 ? '拒绝' : '作废' }}原因：{{ item.statusRemark }}</span>
                </div>
                <el-button slot="reference" type="text">原因</el-button>
              </el-popover>
            </el-col>
            <el-col :span="2" fixed="right">
              <el-button v-if="item.status == 1" @click="operation(2, item)" type="text">通过</el-button>
              <el-button v-if="item.status == 1" @click="operation(4, item)" type="text">拒绝</el-button>
              <el-button v-if="item.status == 2" @click="operation(3, item)" type="text">确认邮寄</el-button>
              <el-button v-if="item.status == 3 || item.status == 2" @click="operation(5, item)" type="text">作废
              </el-button>
            </el-col>
          </el-row>
          <el-row class="v-align-c pad-t-4 pad-b-4 pad-l-10 pad-r-10 sub-row-sty" v-for="(subitem, subindex) of item.invoiceApartManagementDTOList"
            :key="subindex">
            <el-col :span="6">
              <div class="flex-col">
                <span>开票销方：{{subitem.sellerType == 0 ? '平台':'供应商'}}</span>
                <span>销方名称：{{ subitem.sellerName }}
                  <el-popover v-model="subitem.popoverValue" placement="top-start" width="200" trigger="click">
                    <div>
                      <el-input v-model="subitem.editSellerNameValue"></el-input>
                      <div class="flex mar-t-10">
                        <el-button size="mini" @click="subitem.popoverValue = false">取消</el-button>
                        <el-button size="mini" @click="saveSellerName(subitem)" type="primary">确定</el-button>
                      </div>
                    </div>
                    <el-button type="text" v-if="item.status == 1" @click="editSellerName(subitem)" slot="reference"
                      icon="el-icon-edit">
                    </el-button>
                  </el-popover>
                </span>
              </div>
            </el-col>
            <el-col :span="4">
              发票{{subindex + 1}}：￥{{ subitem.amount }}
            </el-col>
            <el-col :span="14">
              <div v-for="(subOrderItem, index) of subitem.projectOrderDTOList" :key="index">
                <div class="v-align-c">
                  <div class="flex-col">
                    <span>平台单号：
                      <img class="width-16 height-16" :src="constant.platformIconObj[subOrderItem.externalPlatformType]" />
                      {{ subOrderItem.externalOrderNo }}</span>
                    <div class="flex v-align-c">
                      <div>系统单号：</div>
                      <el-button type="text" @click='openOrderDetail(subOrderItem)' class="pad-t-0 pad-b-0">{{ subOrderItem.orderNo }}</el-button>
                    </div>
                  </div>
                  <div class="mar-l-20" v-for="(subOrderGoodsItem, index) of subOrderItem.orderGoodsList" :key="index">
                    <el-popover placement="top" width="300" trigger="hover">
                      <div class="flex-col">
                        <span>名称：{{ subOrderGoodsItem.goodsTitle }}</span>
                        <span v-if="item.invoiceMethod == 0">分销价：￥{{ subOrderGoodsItem.distributePrice }}</span>
                        <span
                          v-if="item.invoiceMethod == 1">价格：￥{{ (subOrderGoodsItem.goodsPayAmount / subOrderGoodsItem.goodsNum).toFixed(2) }}</span>
                        <span>数量：{{ subOrderGoodsItem.goodsNum }}</span>
                        <span
                          v-if="item.invoiceMethod == 0">小计：￥{{ (subOrderGoodsItem.distributePrice * subOrderGoodsItem.goodsNum).toFixed(2) }}</span>
                        <span v-if="item.invoiceMethod == 1">小计：￥{{ subOrderGoodsItem.goodsPayAmount }}</span>
                      </div>
                      <el-button slot="reference" type="text">
                        <img class="width-36 height-36" :src="subOrderGoodsItem.goodsImageUrl" alt="">
                      </el-button>
                    </el-popover>
                  </div>
                </div>
              </div>
            </el-col>
          </el-row>
        </div>
        <div
          v-if="!dataList.length"
          class="el-table__empty-block border-b mar-t--10"
          style="height: 100%; width: 100%;">
          <span class="el-table__empty-text">暂无数据</span>
        </div>
      </div>
      <!-- 列表分页 -->
      <div class="pagination">
        <el-pagination background @size-change="handleSizeChange" @current-change="handleCurrentChange"
          :current-page="searchListQuery.currentPage" :page-sizes="[10, 20, 50, 100]" :page-size="searchListQuery.size"
          layout="total, sizes, prev, pager, next, jumper" :total="total">
        </el-pagination>
      </div>
      <el-dialog title="物流信息" :visible.sync="expressFormVisible" :close-on-press-escape="true" width="500px">
        <el-form :model="expressForm" label-position="right" label-width="100px" :rules="rules" ref="dialogExpress"
          class="pad-30">
          <el-form-item label="快递单号:" prop="trackingNo">
            <div>
              <el-input v-model="expressForm.trackingNo" placeholder="请输入快递单号"></el-input>
            </div>
          </el-form-item>
          <el-form-item label="快递公司:" prop="enterpriseExpressId">
            <el-select v-model="expressForm.enterpriseExpressId" placeholder="请选择快递公司">
              <el-option v-for="(item, index) in expressList" :key="index" :label="item.expressName"
                :value="item.enterpriseExpressId" />
            </el-select>
          </el-form-item>
        </el-form>
        <div slot="footer" class="dialog-footer">
          <el-button @click="expressFormVisible = false">取消</el-button>
          <el-button type="primary" @click="saveExpress">确定</el-button>
        </div>
      </el-dialog>
    </div>

  </div>
</template>

<script>
  import elDragDialog from '@/directive/el-dragDialog'
  import {
    pageInvoiceManagement,
    doBatchUpdateStatus,
    statisticalInvoiceStatusNumOrTotalAmount
  } from '@/api/invoice/invoice'
  import {
    listExpress
  } from '@/api/goods/express'
  import {
    getInvoiceContentList
  } from '@/api/invoice/invoiceContent'
  import {
    updateSellerName
  } from '@/api/invoice/invoiceApart'

  export default {
    props: {
      invoiceMethodType: {
        type: Number
      }
    },
    components: {},
    directives: {
      elDragDialog
    },
    data() {
      return {
        total: 0,
        // 表格加载标识
        listLoading: false,
        multipleSelection: [],
        // 查询表单
        searchListQuery: {
          currentPage: 1,
          size: 10,
          // 开票内容ID
          invoiceContentId: '',
          // 发票抬头类型
          invoiceRiseType: '',
          // 发票类型
          invoiceType: ''
        },
        allChecked: false,
        // 表格数据
        dataList: [],
        textCol: 'applyName',
        textValue: '',
        timeCol: 'createTime',
        timeValue: [],
        invoiceStatus: '-1',
        invoiceContentList: [],
        gridData: [],
        checked: false,
        // 快递弹窗
        expressFormVisible: false,
        // 快递列表
        expressList: [],
        expressForm: {
          trackingNo: '',
          enterpriseExpressId: '',
          invoiceId: ''
        },
        rules: {
          trackingNo: [{
            required: true,
            message: '请填写快递单号',
            trigger: 'blur'
          }],
          enterpriseExpressId: [{
            required: true,
            message: '请选择快递公司',
            trigger: 'change'
          }]
        },
        invoiceMethod: {
          0: '申请开票',
          1: '平台代开'
        },
        alreadyOpenedAmount: 0.00,
        pendingReviewAmount: 0.00,
        allLabel: '全部(0)',
        waitCheckLabel: '待审核(0)',
        waitMailedLabel: '待邮寄(0)',
        alreadyMailedLabel: '已寄出(0)',
        notPassLabel: '未通过(0)',
        abolishedLabel: '已作废(0)'
      }
    },
    watch: {
      invoiceMethodType(val) {
        this.initList()
      }
    },
    // 初始化页面
    created() {
      this.initList()
      this.getInvoiceContentList()
    },
    mounted() {},
    methods: {
      // 初始化
      initList() {
        this.listLoading = true
        this.searchListQuery.enterpriseId = this.getEnterpriseId()
        this.searchListQuery.invoiceMethod = this.invoiceMethodType
        if (this.invoiceStatus === '-1') {
          this.searchListQuery.status = ''
        } else {
          this.searchListQuery.status = this.invoiceStatus
        }
        this.searchListQuery.notStatusList = '0'
        this.searchListQuery[this.textCol] = this.textValue
        this.searchListQuery.dateColumn = this.timeCol
        this.searchListQuery.startDate = (this.timeValue && this.timeValue.length > 0) ? this.timeValue[0] : ''
        this.searchListQuery.endDate = (this.timeValue && this.timeValue.length > 1) ? this.timeValue[1] : ''
        // 统计状态和金额
        this.statisticalInvoiceStatusNumOrTotalAmount()
        pageInvoiceManagement(this.searchListQuery).then(response => {
          if (response.isError) return
          const dataList = response.data.records
          dataList.forEach(d => {
            d.managementPopoverValue = false
            d.checked = false
            d.invoiceApartManagementDTOList.forEach(apart => {
              apart.popoverValue = false
              apart.editSellerNameValue = ''
            })
          })
          this.dataList = dataList
          this.total = response.data.total
          this.listLoading = false
          console.log(dataList)
        })
      },
      // 统计状态数量
      statisticalInvoiceStatusNumOrTotalAmount() {
        statisticalInvoiceStatusNumOrTotalAmount(this.searchListQuery).then(response => {
          // 已开票总金额
          let alreadyOpenedAmount = 0
          // 待审核总金额
          let pendingReviewAmount = 0
          // 全部数量
          let allNum = 0
          let waitCheckNum = 0
          let waitMailedNum = 0
          let alreadyMailedNum = 0
          let notPassNum = 0
          let abolishedNum = 0
          if (!response.isError) {
            const resultData = response.data
            if (resultData && resultData.length > 0) {
              resultData.forEach((item) => {
                if (item.typeValue === 1) {
                  waitCheckNum = (item.totalCount || 0)
                  pendingReviewAmount = parseFloat(pendingReviewAmount) + parseFloat((item.totalPrice || 0))
                } else if (item.typeValue === 2) {
                  waitMailedNum = (item.totalCount || 0)
                  alreadyOpenedAmount = parseFloat(alreadyOpenedAmount) + parseFloat((item.totalPrice || 0))
                } else if (item.typeValue === 3) {
                  alreadyMailedNum = (item.totalCount || 0)
                  alreadyOpenedAmount = parseFloat(alreadyOpenedAmount) + parseFloat((item.totalPrice || 0))
                } else if (item.typeValue === 4) {
                  notPassNum = (item.totalCount || 0)
                } else if (item.typeValue === 5) {
                  abolishedNum = (item.totalCount || 0)
                }
                allNum = allNum + (item.totalCount || 0)
              })
            }
          }
          this.allLabel = '全部(' + allNum + ')'
          this.waitCheckLabel = '待审核(' + waitCheckNum + ')'
          this.waitMailedLabel = '待邮寄(' + waitMailedNum + ')'
          this.alreadyMailedLabel = '已寄出(' + alreadyMailedNum + ')'
          this.notPassLabel = '未通过(' + notPassNum + ')'
          this.abolishedLabel = '已作废(' + abolishedNum + ')'
          this.alreadyOpenedAmount = alreadyOpenedAmount.toFixed(2)
          this.pendingReviewAmount = pendingReviewAmount.toFixed(2)
        })
      },
      // 操作（通过、拒绝、邮寄、作废）
      operation(opeartStatus, item) {
        const that = this
        if (!item) {
          that.msgError('请选择要操作的数据!')
          return false
        }
        if (!opeartStatus) {
          that.msgError('未知操作的状态!')
          return false
        }
        // 0:待提交 1:待审核 2:待邮寄 3:已寄出 4:未通过 5:已作废',
        if (opeartStatus === 2) {
          this.$confirm('确定要审核通过吗?', '提示', {
            confirmButtonText: '确定',
            cancelButtonText: '取消',
            type: 'warning'
          }).then(() => {
            that.updateStatusMethod(opeartStatus, item)
          }).catch(() => {})
        } else if (opeartStatus === 3) {
          // 填写物流
          this.expressForm.invoiceId = item.invoiceId
          this.expressForm.applyId = item.applyId
          this.expressForm.enterpriseExpressId = ''
          this.expressForm.trackingNo = ''
          this.expressFormVisible = true
          this.getExpressList()
        } else if (opeartStatus === 4 || opeartStatus === 5) {
          this.$prompt('', opeartStatus === 4 ? '审核不通过' : '申请作废', {
            showClose: false,
            confirmButtonText: '确定',
            cancelButtonText: '取消',
            inputPlaceholder: '请输入' + (opeartStatus === 4 ? '拒绝' : '作废') + '原因',
            inputValidator: function(value) {
              if (!value) {
                return '请输入原因!'
              }
              if (value.length > 200) {
                return '最多只能输入200个字!'
              }
            }
          }).then(({
            value
          }) => {
            that.updateStatusMethod(opeartStatus, item, value)
          }).catch(() => {})
        }
      },
      updateStatusMethod(opeartStatus, item, reason) {
        const invoiceIdList = [item.invoiceId]
        const params = {
          invoiceIdList: invoiceIdList,
          status: opeartStatus,
          enterpriseId: this.getEnterpriseId(),
          statusRemark: reason
        }
        doBatchUpdateStatus(params).then(response => {
          if (response.isError) return
          this.$message({
            type: 'success',
            message: '操作成功！'
          })
          this.initList()
        })
      },
      // 跳转到订单列表 type： 1-待审核; 2-已开票;
      openOrderList(type) {
        if (!type) {
          this.$message({
            type: 'error',
            message: '订单参数错误!'
          })
          return
        }
        const invoiceMethodType = this.invoiceMethodType
        // pageSource： 0-申请开票； 1-平台开票
        let pageSource = 0
        if (invoiceMethodType === 1) {
          pageSource = 1
        }
        const routeData = this.$router.resolve({
          path: '/order/order/distribution/list',
          query: {
            pageSource: pageSource,
            // type：1-待审核金额详情; 2-已开票金额详情；
            buttonType: type
          }
        })
        window.open(routeData.href, '_blank')
      },
      // 跳转到订单详情
      openOrderDetail(row) {
        const routeData = this.$router.resolve({
          path: '/order/order/detail/index',
          query: {
            orderId: row.orderId
          }
        })
        window.open(routeData.href, '_blank')
      },
      // 获取物流信息
      getExpressList() {
        listExpress({
          enterpriseId: this.getEnterpriseId(),
          supplierId: this.getSupplierId(),
          expressStatus: 1
        }).then(response => {
          if (response.isError) return
          this.expressList = response.data
        })
      },
      // 保存快递信息
      saveExpress() {
        const invoiceId = this.expressForm.invoiceId
        const enterpriseExpressId = this.expressForm.enterpriseExpressId
        const trackingNo = this.expressForm.trackingNo
        if (!invoiceId) {
          this.$message({
            type: 'error',
            message: '发票ID不能为空！'
          })
        }
        this.$refs['dialogExpress'].validate((valid) => {
          if (valid) {
            const invoiceIdList = [invoiceId]
            const params = {
              invoiceIdList: invoiceIdList,
              // 填写物流之后变成已寄出状态
              status: 3,
              enterpriseId: this.getEnterpriseId(),
              expressId: enterpriseExpressId,
              trackingNo: trackingNo
            }
            doBatchUpdateStatus(params).then(response => {
              if (response.isError) return
              this.$message({
                type: 'success',
                message: '操作成功！'
              })
              this.expressFormVisible = false
              this.initList()
            })
          }
        })
      },
      // 获取开票内容列表
      getInvoiceContentList() {
        getInvoiceContentList({
          enterpriseId: this.getEnterpriseId()
        }).then(response => {
          if (response.isError) return
          this.invoiceContentList = response.data
        })
      },
      // 点击修改销方名称
      editSellerName(subitem) {
        subitem.popoverValue = true
        subitem.editSellerNameValue = subitem.sellerName
      },
      // 保存销方名称
      saveSellerName(subitem) {
        const invoiceApartId = subitem.invoiceApartId
        const sellerName = subitem.editSellerNameValue
        updateSellerName({
          invoiceApartId: invoiceApartId,
          sellerName: sellerName
        }).then(response => {
          if (response.isError) return
          subitem.sellerName = sellerName
          subitem.popoverValue = false
        })
      },
      // 状态页切换
      invoiceStatusClick() {
        this.searchListQuery.currentPage = 1
        this.initList()
      },
      // 批量通过
      batchApproved() {
        const invoiceIdList = []
        this.dataList.forEach(e => {
          if (e.checked) {
            invoiceIdList.push(e.invoiceId)
          }
        })
        if (invoiceIdList.length <= 0) {
          this.$message({
            type: 'error',
            message: '请选择数据！'
          })
        }
        const params = {
          invoiceIdList: invoiceIdList,
          // 审核通过变成待邮寄状态
          status: 2,
          enterpriseId: this.getEnterpriseId()
        }
        doBatchUpdateStatus(params).then(response => {
          if (response.isError) return
          this.$message({
            type: 'success',
            message: '操作成功！'
          })
          this.initList()
        })
      },
      // 全选事件
      selectAll() {
        let checkedStatus = false
        this.multipleSelection.length = 0
        if (this.allChecked === true) {
          checkedStatus = true
          this.multipleSelection.length = this.dataList.length
        }
        this.dataList.forEach(d => {
          d.checked = checkedStatus
        })
      },
      // 勾选事件
      checkedChange(checked) {
        const len = this.dataList.length
        if (checked === true) {
          this.multipleSelection.length = this.multipleSelection.length + 1
        } else {
          this.multipleSelection.length = this.multipleSelection.length - 1
        }
        if (this.multipleSelection.length === len) {
          this.allChecked = true
        } else {
          this.allChecked = false
        }
      },
      // 全选事件
      handleSelectionChange(val) {
        this.multipleSelection = val
        if (this.multipleSelection.length === this.dataList.length) {
          this.allChecked = true
        } else {
          this.allChecked = false
        }
      },
      // 查询事件
      handleSearch() {
        this.searchListQuery.currentPage = 1
        this.initList()
      },
      // 重置事件
      resetSearch() {
        const originData = this.$options.data()
        this.textCol = originData.textCol
        this.textValue = originData.textValue
        this.timeCol = originData.timeCol
        this.timeValue = originData.timeValue
        this.searchListQuery = originData.searchListQuery
        this.initList()
      },
      // 更改当前页数
      handleCurrentChange(val) {
        this.searchListQuery.currentPage = val
        this.initList()
      },
      // 更改当前页面大小
      handleSizeChange(val) {
        this.searchListQuery.size = val
        this.initList()
      }
    }
  }
</script>
<style lang="less" scoped>
  .pop-layer-tab.el-table{
    &:before{
      content: '';
      display: none;
    }
  }
  .sub-row-sty{
    border-bottom: #f2f3f8 1px solid;
    &:last-child{
      border-bottom: none;
    }
  }
  .top-operate {
    margin-bottom: 0;
    height: 85px;
    background-color: #f7f8fa;
    display: flex;
    align-items: center;
    white-space: nowrap;
    flex-wrap: nowrap;
    width: 100%;
    overflow-x: auto;
  }

  .search-item {
    flex-shrink: 0;
    padding: 0 20px;

    >div,
    .el-cascader {
      margin-right: 0px;
    }

    label {
      font-weight: unset;
    }

    .el-input {
      width: 200px;
    }
  }

  .btn-search {
    height: 60px;
    display: flex;
    align-items: center;
  }

  .table-container {
    /deep/.el-table th>.cell {
      padding-left: 14px;
    }
  }

  .bgc-default {
    /deep/ .el-dialog__body {
      padding-bottom: 140px;
    }
  }

  .platform_class {
    border: 1px solid #ebb563;
    border-radius: 4px;
    color: #e6a23c;
    background-color: #fdf6ec;
    padding: 3px;
    font-size: 10px;
  }

  .apply_class {
    border: 1px solid #66b1ff;
    border-radius: 4px;
    color: #409eff;
    background-color: #ecf5ff;
    padding: 3px;
    font-size: 10px;
  }
</style>
